package com.activeharmony.sample;

import com.activeharmony.Configuration;
import com.activeharmony.Model;
import com.activeharmony.annotation.Table;

import java.io.IOException;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

/**
 * ConfigurationTest Class.
 */
public class ConfigurationTest extends ExampleOhosTest {
    /**
     * validateDefaultValue
     *
     * @throws IOException
     * @throws ClassNotFoundException
     */
    public void validateDefaultValue() throws IOException, ClassNotFoundException {
        Configuration configuration = new Configuration.Builder(getContext()).create();
        assertNotNull(configuration.getContext());
        assertEquals(1024, configuration.getCacheSize());
        assertEquals("Application.db", configuration.getDatabaseName());
        assertEquals(1, configuration.getDatabaseVersion());
        assertNull(configuration.getModelClasses());
        assertFalse(configuration.isValid());
        assertNull(configuration.getTypeSerializers());
        assertEquals(Configuration.SQL_PARSER_LEGACY, configuration.getSqlParser());
    }

    /**
     * testCreateConfigurationWithMockModel
     */
    public void testCreateConfigurationWithMockModel() {
        Configuration configuration = new Configuration.Builder(getContext())
                .addModelClass(SampleTestModel.class)
                .create();
        List<Class<? extends Model>> modelClasses = configuration.getModelClasses();
        assertEquals(1, modelClasses.size());
        assertTrue(configuration.isValid());
    }

    @Table(name = "SampleTestModel")
    private static class SampleTestModel extends Model {
    }
}
